1313A - Fast Food Restaurant - CodeForces Solution


brute force greedy implementation *900

Please click on ads to support us..

Python Code:

t=int(input())
def brute(ind,su=[0,0,0],co=0):
    global ma
    if ind==7:
        if su[0]<=a and su[1]<=b and su[2]<=c:
            ma=max(ma,co)
        return
    brute(ind+1,[su[i]+aa[ind][i] for i in range(3)],co+1)
    brute(ind+1,su,co)
for i in range(t):
    a,b,c=list(map(int,input().split()))
    ma=0
    aa=[[1,1,1],[1,1,0],[1,0,0],[1,0,1],[0,1,1],[0,1,0],[0,0,1]]
    brute(0)
    print(ma)

C++ Code:

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

#define ll         long long

#define frp(a, b)  for(ll i = a; i < b; i++)
#define frn(a, b)  for(ll i = a-1; i >= b; i--)

#define V2         vector < vector<ll> > v(n, vector <ll> (n));

#define in(x)      insert(x)
#define pb(x)      push_back(x)
#define full(x)    x.begin(),x.end()

#define check      cout << "aiseee" <<endl;
#define start      int test; cin >> test; while(test--)

void setup();
void nahid();
void ishan();

int main()
{
	
	setup();
	// nahid();
	ishan();
	return 0;
}

void nahid()
{
	// cout << "hel" << endl;
	start
	{
		// cout << "hel" << endl;
		// check
		ll n, k; cin >> n >> k;

		ll remem = 0;
		map <int, int> mp;
		for(ll i = 0; i < n; i++)
		{
			ll l, r; cin >> l >> r;

			if(l <= k && k <= r)
			{
				for(ll j = l; j <= r; j++)
				{
					mp[j]++;
				}
			}
		}

		// cout << mp[k] << endl;
		ll mx = 0;
		for(auto &t : mp)
		{
			ll tmp = t.second;

			mx = max(mx, tmp);
		}

		// cout << mx << endl;
		ll c = 0;

		for(auto &t : mp) if(mx == t.second) c++;

		// cout << c << endl;

		if(mp[k] == 0 || c > 1) cout << "NO" << endl;
		else cout << "YES" << endl;




	}
}

void ishan()
{
	start
	{
		
		ll a, b, c; cin >> a >> b >> c;

		ll happy = 0;

		if(a+b+c == 0) cout << 0 << endl;
		else if(a >= 4 && b >= 4 && c >= 4) cout << 7 << endl;
		else
		{

			if(a < b) swap(a, b);
			if(a < c) swap(a, c);
			if(b < c) swap(b, c);

			if(a > 0)
			{
				a--;
				happy++;
			}
			if(b > 0)
			{
				b--;
				happy++;
			}
			if(c > 0)
			{
				c--;
				happy++;
			}

			if(a > 0 && b > 0)
			{
				a--;
				b--;
				happy++;
			}

			if(a > 0 && c > 0)
			{
				a--;
				c--;
				happy++;
			}

			if(b > 0 && c >> 0)
			{
				b--;
				c--;
				happy++;
			}

			if(a > 0 && b > 0 && c > 0)
			{
				a--;
				b--;
				c--;
				happy++;
			}

			

			cout << happy << endl;

		}


	}
}

void setup()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
#endif
}

/*
		|-------------------------------------------------------------------------------------|
		| #     #      #      #   #  ###  ####          ###  ####  #  #      #      #      #  |
		| # #   #     # #     #   #   #   #   #          #   #     #  #     # #     # #    #  |
		| #  #  #    #####    #####   #   #    #   AKA   #   ####  ####    #####    #   #  #  |
		| #   # #   #     #   #   #   #   #   #          #      #  #  #   #     #   #    # #  |
		| #     #  #       #  #   #  ###  ####          ###  ####  #  #  #       #  #      #  |
		|-------------------------------------------------------------------------------------|
*/


Comments

Submit
0 Comments
More Questions

892A - Greed
32A - Reconnaissance
1236D - Alice and the Doll
1207B - Square Filling
1676D - X-Sum
1679A - AvtoBus
1549A - Gregor and Cryptography
918C - The Monster
4B - Before an Exam
545B - Equidistant String
1244C - The Football Season
1696B - NIT Destroys the Universe
1674A - Number Transformation
1244E - Minimizing Difference
1688A - Cirno's Perfect Bitmasks Classroom
219A - k-String
952A - Quirky Quantifiers
451B - Sort the Array
1505H - L BREAK into program
171E - MYSTERIOUS LANGUAGE
630D - Hexagons
1690D - Black and White Stripe
1688D - The Enchanted Forest
1674C - Infinite Replacement
712A - Memory and Crow
1676C - Most Similar Words
1681A - Game with Cards
151C - Win or Freeze
1585A - Life of a Flower
1662A - Organizing SWERC